<?php

/**
 * This is the model class for table "merchant".
 *
 * The followings are the available columns in table 'merchant':
 * @property string $allpay_mno
 * @property string $name
 * @property string $id_wxplatform
 * @property string $mchreturn
 * @property string $feerate
 * @property string $remain_cash
 * @property string $createtime
 * @property string $is_active
 * @property string $status
 * @property string $province
 * @property string $total_remain_cash
 */
class Merchant extends ActiveRecord
{
    //激活条件(大于等于5元)
    const MIN_AMOUNT = 500;
    //激活状态
    const ACTIVE = 1;
    const NO_ACTIVE = 0;

    //正常状态
    const ENABLE_STATUS = '1';
    //套现状态（停用）
    const CASHOUT_STATUS = '2';
    //刷单状态（停用）
    const RISK_STATUS = '3';
    //警告状态
    const WARNING_STATUS = '4';

    const DISABLE_DESC = array(
        '2' => '该店涉嫌套现行为，已被暂时关停',
        '3' => '该店涉嫌刷单行为，已被暂时关停',
    );

    const EXCEPTION_STATUS_YELLOW = '2';
    const EXCEPTION_STATUS_RED = '1';

    //免手续费时间
    const FREE_START_TIME = '2018-08-01 00:00:00';
    const FREE_END_TIME = '2018-08-31 23:59:59';
    //免手取费条件(小余等于于200元)
    const FREE_MAX_AMOUNT = 200;
    const FREE_PROVINCES = array('河北省', '河北');

	protected $_curl;
	public function init()
	{
		$this->_curl = new Curl();
	}
	
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Merchant the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'merchant';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('allpay_mno, name, mchreturn, id_wxplatform, feerate, remain_cash, createtime', 'safe'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
		);
	}
	
	public function getWxplatform()
	{
		return Wxplatform::model()->findByAttributes(array(
			'id_wxplatform' => $this->id_wxplatform
		));
	}
	
	public static function decodeMno($enMno)
	{
	    $step1 = base64_decode($enMno, true);
	    $step2 = strrev($step1);
	    $step3 = base64_decode($step2, true);
	
	    return $step3;
	}
	
	public static function decodeTno($enTno)
	{
		$step1 = base64_decode($enTno, true);
		$step2 = strrev($step1);
		$step3 = base64_decode($step2, true);
		
		return $step3;
	}
}
